/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-11-27 下午4:16 Created by dwzhang
 */
package com.jade.bss.api.controller;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.jade.framework.base.util.ResponseUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 判断token是否有效。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-11-27 下午4:16
 */
@Controller
@RequestMapping (value = "/token")
public class TokenController
{
    @RequestMapping (value = "/validate.json")
    @ResponseBody
    public void login(HttpServletResponse response)
            throws Exception
    {
        Subject subject = SecurityUtils.getSubject();
        Map<String, Object> map = new HashMap<String, Object>();
        if (subject == null || subject.getPrincipal() == null) {
            map.put("token_valid", false);
        }
        else {
            map.put("token_valid", true);
        }
        ResponseUtils.writeSuccessResult(response, map);
    }
}
